#!/usr/bin/env python3
# coding: utf-8
##############################################################
## 通用函数
## harrydeep@wardyan.top 20220212
##############################################################

import datetime
# from selenium import webdriver
# ##from selenium import By
# from selenium.webdriver.chrome.options import Options
# from selenium.webdriver.common.by import By





def current_timestamp() :
    """
        返回当前时间戳的字符串, 带3位毫秒
    """
    return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]

def formatdatetime(dt) -> str :
    if dt is None :
        return None
    else :
        return dt.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]


def formatdatetimetype(dt,type) -> str :
    """
    type: 类型, 1当天开始, 2当天结束
    """
    if dt is None :
        return None
    else :
        if type is None :
            type = 1
        if type == 1 :
            return dt.strftime("%Y-%m-%d 00:00:00.000")
        elif type == 2 :
            return dt.strftime("%Y-%m-%d 23:59:59.997")
        else :
            return dt.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]


# def get_browser(options=None) :
#     # 创建一个参数对象，用来控制chrome以无界面模式打开
#     chrome_options = Options()
#     chrome_options.add_argument('--headless')
#     chrome_options.add_argument('--disable-gpu')
#     # 驱动路径
#     ##path = r'E:\\company\\xwork\\python\\sync\\chromedriver.exe'
    
#     chrome_options.add_argument('Host=www.tapd.cn')
#     chrome_options.add_argument('User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0')
#     chrome_options.add_argument('Accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8')
#     chrome_options.add_argument('Accept-Language=zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2')
#     chrome_options.add_argument('Accept-Encoding=gzip, deflate, br')
#     chrome_options.add_argument('DNT=1')
#     chrome_options.add_argument('Connection=keep-alive')
#     chrome_options.add_argument('Cookie=fb_pool1148654625001001970sort=created%7EDESC; tui_filter_fields=%5B%22name%22%2C%22owner%22%2C%22iteration_id%22%2C%22priority%22%5D; 1944296355_48654625_/prong/tasks/index_remember_view=1148654625001001970; tflnewfilter_task_status=close; 48654625_1148654625001000006_story_create_template=1148654625001000013; tapdsession=1646700053797404aebed8c85683d1202d12c553868ed5938fcfe7468f947085b5502d24a3; __root_domain_v=.tapd.cn; _qddaz=QD.317146699952880; t_u=ed3a7e6f17f36ba239b0929255fa6278630400ed9980dd9e7ebfaa3d5c9cc0e56eabf13f17d8034df9746862699efde9c7d5680557fc184ac6e44fb6c50bdde9fcbd49fc6f3479c8%7C1; new_worktable=created%7C48654625%7C62%7Cexpiration_date; 53705586_1153705586001000008_story_create_template=1153705586001000019; 48654625_1148654625001000006_story_create_template=1148654625001000013; _t_uid=1944296355; _t_crop=48966209; tapd_div=101_8; dsc-token=NzhQRDUlS3DT2GDY; _qddab=3-ipd186.l42fvkkv')
#     chrome_options.add_argument('Upgrade-Insecure-Requests=1')
#     chrome_options.add_argument('Sec-Fetch-Dest=document')
#     chrome_options.add_argument('Sec-Fetch-Mode=navigate')
#     chrome_options.add_argument('Sec-Fetch-Site=none')
#     chrome_options.add_argument('Sec-Fetch-User=?1')

#     chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])

#     if options is not None :
#         for option in options :
#             chrome_options.add_argument(option)

#     # 创建浏览器对象
#     browser = webdriver.Chrome(chrome_options=chrome_options)  # 参数添加
#     return browser













# if __name__ == '__main__':
#     print(formatdatetime(datetime.datetime.now()))
#     print(formatdatetimetype(datetime.datetime.now(),1))
#     print(formatdatetimetype(datetime.datetime.now(),2))
#     print(formatdatetimetype(datetime.datetime.now(),3))